<template>
	<view class="my_profile " @click="$doubleClick(detail)">
		
		
		<view class="flex">
			<view class="photo">
				<image class="good_img" :src="ware.main_image==''?imgRemote+config.item_default:imgRemote+ware.main_image"
					mode="widthFix"></image>
			</view>
			
			<block v-if="ware==undefined"></block>
			<block v-else>
				<view class="info">
					<view class="operate flex">
						<view style="width:86%;" @click="$doubleClick(detail)">
							<view class="fs-13 two-line name">{{ware.name}}</view>
							
							<view class="label_box" v-if="ware.label">
								<view class="label" v-for="(items,indexs) in ware.label" :key="indexs">
									{{items.name}}
								</view>
							</view>
							
							<view class="desc">{{ware.desc}}</view>
							
							
							
							<view v-if="ware.tag_data" class="tag">
								<text v-for="(item,index) in ware.tag_data.split(',')" :key="index">
									
									{{item=='new'?'新品':(item=='group'?'团购':'推荐')}}
								</text>
							</view>
						</view>
					</view>
				</view>
			</block>
			
		</view>
		
		<view class="btn_box">
			
			<view class="red_font fs-18">¥ {{ware.sku[0].market_price}}</view>
			<view class="btn">预约</view>
		</view>

		


	</view>
</template>

<script>
	const app = getApp().globalData;
	const {
		imgRemote
	} = app;
	let {
		log
	} = console;
	export default {
		props: ['wares', 'config', 'url'],
		watch: {
			wares(newvalue) {
				this.ware = newvalue;
			}
		},
		data() {
			return {
				apliyShow: false,
				ware: this.wares,
				imgRemote: imgRemote,
				token: uni.getStorageSync('cdj_token'),
				count: 0,
				addcount: 0,
				message: ''
			}
		},
		methods: {
			showCart() {
				this.$emit('showCart')
			},
			addcart(url, num, message = '成功加入购物车') {
				getApp().globalData.aplipay = false;
				let item = this.ware;
				if (item.is_float == 1 && !Number.isInteger(Number(num))) {
					rs.Toast('购买数量不能为小数');
					return;
				}
				let timeStamp = Math.round(new Date().getTime() / 1000);
				let obj = {
					appid: appid,
					timeStamp: timeStamp,
					item_id: item.id,
					attr_id: 0,
					item_num: num
				};
				let sign = md5.hexMD5(rs.objKeySort(obj) + appsecret);
				let params = Object.assign({
						sign: sign
					},
					obj
				);
				rs.postRequests(url, params, res => {
					let data = res.data;
					if (data.code == 200) {
						// #ifndef MP-ALIPAY
						rs.Toast(message);
						// #endif


						if (num <= 0) {
							this.ware.cart_num = 0;
						} else {

							this.ware.cart_num = num;

						}
					} else if (data.code == 407 || data.code == 406) {
						rs.Toast("购买数量不能超过活动数量");
					} else {
						rs.Toast(res.data.msg);
					}
				});
			},
			minus(e) {
				if (e == 0) {
					this.addcart('deleteCart', e, '成功删除商品');
				} else {
					this.addcart('changeNum', e);
				}
			},
			plus(e) {
				this.addcart('changeNum', e);
			},
			plusCart() {

				this.addcart('changeNum', 1);
			},
			showKey() {
				this.$emit('showKey')
			},
			detail() {
				uni.navigateTo({
					url: `/pages/index/shopdetail?id=${this.ware.id}`
				})
			},
			cancelCollect() {
				this.$emit('cancelCollect')
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my_profile {
		/* padding: 0 0 30rpx 0; */
		background: white;
		border-bottom: 1px solid #eee;
		.tag text {
			background: $m-c;
			color:white;
			font-size: 24rpx;
			border-radius: 10rpx;
			margin-right: 10rpx;
			padding: 0 10rpx;
		}
	}

	.my_profile .photo {

		/* width: 180rpx; */

	}

	.my_profile .good_img {
		margin: 29rpx 29rpx 0 29rpx;
		border-radius: 10rpx;
		width: 180rpx;
		height: 180rpx;
	}

	.my_profile .info {
		flex: 1;
		display: flex;
		padding: 29rpx 0;
		flex-direction: column;
		justify-content: space-between;
		width: 0;
	}

	.my_profile .operate {
		height: 100%;
		justify-content: space-between;
	}

	.my_profile .add_cart {
		width: 44.4rpx;
		height: 44.4rpx;
		background: #FF7133;
		text-align: center;
		line-height: 44.4rpx;
		border-radius: 50%;
		color: white;
		margin: -20rpx 30rpx 0 0;
	}

	.my_profile .showToast {
		position: fixed;
		margin: auto;
		left: 0;
		right: 0;
		top: 12px;
		bottom: 0;
		width: 200rpx;
		height: 30rpx;
		background: rgba(0, 0, 0, 0.7);
		border-radius: 10rpx;
		padding: 15rpx;
		color: white;
	}
	.name{
		font-weight: bold;
	}
	.desc{
		font-size: 24rpx;
		margin: 10rpx 0;
	}
	.label_box{
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}
	.label{
		font-size: 24rpx;
		margin: 10rpx 10rpx 0 0;
		background-color:#F7ECE4;
		color:#EF8200;
		box-sizing: border-box;
		padding: 6rpx 20rpx;
		border-radius: 10rpx;
	}
	.btn_box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 0 29rpx 10rpx 29rpx;
	}
	.btn{
		background-color: #EF8200;
		color: white;
		box-sizing: border-box;
		padding: 10rpx 35rpx;
		border-radius: 15rpx;
		
	}
</style>
